# -.- coding:utf-8 -.-
import boto3
import json

def msgModel(choose):
    msg = None
    tp = 'tp'

    serialId = 'asatsy';
    deviceId = '9E1BB2C0-7BAB-CE40-B9A9-ABF52D774D76';
    tabNo = '啊啊啊';

    if choose == 'cx':
        msg = {
            "type": "debug",
            "method": "km:batch_cart",
            "groupId": serialId,
            "pointId": "km##%s##%s" % (serialId, deviceId),
            'data': [
                {
                    'rn': '1',
                    'method': 'debug:atcspn',
                    'cmd': 'ZDCX~001\r\n105     6037028',
                    'pack': {
                        'content': ''
                    }
                }
            ]
        }
    if choose == 'kt':
        msg = {
            "type": "debug",
            "method": "km:batch_cart",
            "groupId": serialId,
            "pointId": "km##%s##%s" % (serialId, deviceId),
            'data': [
                {
                    'rn': '1',
                    'method': 'debug:aspdgr',
                    'cmd': 'KT   190\r\n1      ',
                    'pack': {
                        'content': ''
                    }
                }
            ]
        }
    if choose == 'writefile':
        msg = {
            'type': 'child',
            'groupId': serialId,
            'pointId': deviceId,
            'method': 'child:writefile',
            'data': {
                'path': 'C:/khldata/en_d.txt',
                'text': '1'
            }
        }
    if choose == 'alert':
        msg = {
            'type': 'child',
            'groupId': serialId,
            'pointId': deviceId,
            'method': 'child:alert',
            'data': 'aaaaaa'
        }
    if choose == 'SecondPayMsg':
        msg = {
            'wid': '11187',
            'userId': '',
            'shopId': '',
            'tabId': '0',
            'trackingUU': '',
            'serialId': serialId,
            'tabNo': tabNo
        }
        tp = 'net.kehuilai.models.sqs.dc.SecondPayMsg'

	return (msg, tp)

# 发送方法
def send(name, message, type):
    sqs = boto3.resource('sqs')
    queue = sqs.get_queue_by_name(QueueName=name)
    queue.send_message(
        MessageBody=message,
        MessageAttributes={
            '_type_': {
                'DataType': 'String',
                'StringValue': type,
            }
        }
    )

if __name__ == '__main__':
    (msg, tp) = msgModel('SecondPayMsg')
    if msg == None:
    	print "msg is none"
    else:
        message = json.dumps(msg)
        send('dc-parser', message, tp)
        print '发送测试指令: ' + message
